// pages/fangdetail/fangdetail.js
import cache from '../../utils/Cache.js';
import url from '../../utils/url.js';
import http from '../../utils/http.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    autoplay: true,
    indicatorDots: true,
    circular: true,
    easingFunction: 'easeInOutCubic',
    fangDetail:{},
	markers: [],
	shoucangtext:'',
	shoucangstatus : ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id = options.id;
    this.getPicList(id)
	this.favfind(id)
  },
  //获取轮播列表
  getPicList:function(id){
    let that = this;
    http.http(url.fangDetail+'/'+id,'GET',{},function(res){
      console.log(res)
        that.setData({
          fangDetail:res,
		  markers:[{
			  iconPath: "../../images/icon/baidu.jpeg",
			  id: id,
			  latitude: res.latitude,
			  longitude: res.longitude,
			  width: 50,
			  height: 50
		  }]
        });
    });
  },

  
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
		if(res.form == 'button'){
			return {
				title:this.fangDetail.name,
				path:'/pages/fangdetail/fangdetail?id='+this.fangDetail.id,
				imageUrl:this.fangDetail.pic
			};
		}
  },
  //添加收藏
  addFavFun(evt){
      console.log(evt)
  },
  //底部添加收藏
  addfav:function(evt){
	  let that = this;
	  let id = evt.currentTarget.dataset.id;
	  http.http(url.favadd,'POST',{fang_id:id,openid:cache.getSorg('openid')},function(res){
		  wx.showToast({
			  title:'收藏成功',
			  icon:'none'
		  });
		  that.setData({
		  	shoucangstatus:1,
		  	shoucangtext:'取消收藏'
		  });
	  });
  },
  //查询房源的收藏状态
  favfind:function(id){
	  let that = this;
	http.http(url.favfind,'GET',{id:id,openid:cache.getSorg('openid')},function(res){
		that.setData({
			shoucangstatus:res.status,
			shoucangtext:res.msg
		});
	});
  },
  //取消收藏
  delfav:function(evt){
		let that = this;
		let id = evt.currentTarget.dataset.id;
		http.http(url.favsdel,'GET',{id:id,openid:cache.getSorg('openid')},function(res){
			wx.showToast({
				title:'取消收藏成功',
				icon:'none'
			})
			that.setData({
				shoucangstatus:-1,
				shoucangtext:'添加收藏'
			});
		});
  },
})